package com.talkweb.securitycamera.data.hadoopDB;

import com.talkweb.securitycamera.common.interfaces.dataprocess.FileCallback;
import ohos.app.Context;
import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0.1
 * @description:分布式数据库提供工具
 * @program: security-camera
 * @Author xiaozhijun
 * @Date 2021/1/28 16:14
 */
public class HadoopDbFactory {
    private static class HadoopDbFactoryHolder {
        public static HadoopDbFactory instance = new HadoopDbFactory();
    }

    private HadoopDbFactory() {
    }

    /**
     * 数据库缓存
     */
    private Map<String, HadoopHelper> hadoopMap = new HashMap();

    public static HadoopDbFactory getInstance() {
        return HadoopDbFactoryHolder.instance;
    }

    /**
     * 打开指定的数据库
     * @param context
     * @param storeId
     * @return
     */
    public synchronized HadoopHelper openHadoop(Context context, String storeId, FileCallback fileCallback) {
        if (!hadoopMap.containsKey(storeId)) {
            hadoopMap.put(storeId, new HadoopHelper(context, storeId, fileCallback));
        }
        return hadoopMap.get(storeId);
    }

}
